#include "selectsort.h"
#include <QThread>

SelectSort::SelectSort(QObject *parent):
    IAlgo(parent)
{

}

QString SelectSort::name()
{
    return "Select Sort";
}

void SelectSort::run()
{
    _run_time = 0;
    QVector<int> &data = _data->GetData();
    for(int i = data.size() - 1; i >= 0; --i){
        int max_pos = 0;
        for(int j = 1; j <= i; ++j){
            if(data[j] > data[max_pos]){
                max_pos = j;
            }
            _run_time ++;
        }
        qSwap(data[i], data[max_pos]);
        _data->Refresh();
        if(_interval > 0){
            QThread::msleep(_interval);
        }
    }
}
